/*    */ package com.equipmentmanage.controller;
/*    */ 
/*    */ import com.equipmentmanage.model.EquipmentType;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.service.EquipmentService;
import com.equipmentmanage.service.EquipmentTypeService;
import com.equipmentmanage.util.PageUtil;
import com.equipmentmanage.util.ResponseUtil;
import com.equipmentmanage.util.StringUtil;

/*    */ import java.util.List;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"/equipmentType"})
/*    */ public class EquipmentTypeController
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private EquipmentTypeService equipmentTypeService;
/*    */ 
/*    */   @Autowired
/*    */   private EquipmentService equipmentService;
/*    */ 
/*    */   @RequestMapping({"/list"})
/*    */   public ModelAndView list(@RequestParam(value="page", required=false) String page, EquipmentType s_equipmentType, HttpServletRequest request)
/*    */   {
/* 42 */     ModelAndView mav = new ModelAndView();
/* 43 */     HttpSession session = request.getSession();
/* 44 */     if (StringUtil.isEmpty(page)) {
/* 45 */       page = "1";
/* 46 */       session.setAttribute("s_equipmentType", s_equipmentType);
/*    */     } else {
/* 48 */       s_equipmentType = (EquipmentType)session.getAttribute("s_equipmentType");
/*    */     }
/* 50 */     PageBean pageBean = new PageBean(Integer.parseInt(page), 3);
/* 51 */     List equipmentTypeList = this.equipmentTypeService.find(pageBean, s_equipmentType);
/* 52 */     int total = this.equipmentTypeService.count(s_equipmentType);
/* 53 */     String pageCode = PageUtil.getPagation(request.getContextPath() + "/equipmentType/list.do", total, Integer.parseInt(page), 3);
/* 54 */     mav.addObject("pageCode", pageCode);
/* 55 */     mav.addObject("modeName", "设备类型管理");
/* 56 */     mav.addObject("equipmentTypeList", equipmentTypeList);
/* 57 */     mav.addObject("mainPage", "jsp/equipmentType/list.jsp");
/* 58 */     mav.setViewName("main");
/* 59 */     return mav;
/*    */   }
/*    */ 
/*    */   @RequestMapping({"/preSave"})
/*    */   public ModelAndView preSave(@RequestParam(value="id", required=false) String id) {
/* 64 */     ModelAndView mav = new ModelAndView();
/* 65 */     mav.addObject("mainPage", "jsp/equipmentType/save.jsp");
/* 66 */     mav.addObject("modeName", "设备类型管理");
/* 67 */     mav.setViewName("main");
/* 68 */     if (StringUtil.isNotEmpty(id)) {
/* 69 */       mav.addObject("actionName", "设备类型修改");
/* 70 */       EquipmentType equipmentType = this.equipmentTypeService.loadById(Integer.parseInt(id));
/* 71 */       mav.addObject("equipmentType", equipmentType);
/*    */     } else {
/* 73 */       mav.addObject("actionName", "设备类型添加");
/*    */     }
/* 75 */     return mav;
/*    */   }
/*    */ 
/*    */   @RequestMapping({"/save"})
/*    */   public String save(EquipmentType equipmentType) {
/* 80 */     if (equipmentType.getId() == null)
/* 81 */       this.equipmentTypeService.add(equipmentType);
/*    */     else {
/* 83 */       this.equipmentTypeService.update(equipmentType);
/*    */     }
/* 85 */     return "redirect:/equipmentType/list.do";
/*    */   }
/*    */ 
/*    */   @RequestMapping({"/delete"})
/*    */   public void delete(@RequestParam("id") String id, HttpServletResponse response) throws Exception {
/* 90 */     JSONObject result = new JSONObject();
/* 91 */     if (this.equipmentService.existEquipmentByTypeId(Integer.parseInt(id))) {
/* 92 */       result.put("errorInfo", "该设备类型下存在设备，不能删除！");
/*    */     } else {
/* 94 */       this.equipmentTypeService.delete(Integer.valueOf(id).intValue());
/* 95 */       result.put("success", Boolean.valueOf(true));
/*    */     }
/* 97 */     ResponseUtil.write(result, response);
/*    */   }
/*    */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.controller.EquipmentTypeController
 * JD-Core Version:    0.6.1
 */